package net.learn2develop.view;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html.ImageGetter;

public class HttpImageGetter implements ImageGetter {

	  @Override
	  public Drawable getDrawable(String source) {
	    try {
	      URL url = new URL(source);
	      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
	      conn.setDoInput(true);
	      conn.connect();
	      InputStream is = conn.getInputStream();
	      BitmapDrawable dr = new BitmapDrawable(BitmapFactory.decodeStream(is));
	      dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
	      return dr;
	   } catch (IOException e) {
	    e.printStackTrace();
	    return null;
	  }
}
}